# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
from airtest.core.android.android import Android
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
using("SideMenu_Open.air")
import SideMenu_Open
        
class SideMenu_Share(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        # 打开左侧菜单
        isOpenSideMenu = SideMenu_Open.runTest({})
        if not isOpenSideMenu:
            return False

        # 获取左侧菜单节点
        bottomPanel = poco("bottom_panel")
        if not bottomPanel.exists():
            return False

        btnShare = bottomPanel.offspring("share_btn")
        if not btnShare.exists():
            return False

        self.clickButton(btnShare)

        try:
            poco("share_panel").wait_for_appearance()
        except:
            assert(True, True, "代理面板正常弹出")
            return False

        sharePanel = poco("share_panel")

        btnWx = sharePanel.offspring("btn_share_wx")
        if not btnWx.exists():
            return False

        self.clickButton(btnWx)

        sleep(2.0)

        try:
            pos = assert_exists(Template(r"tpl1534498156734.png", record_pos=(-0.397, -0.34), resolution=(1080, 1920)), "请填写测试点")

            android = Android()
            displayInfo = android.display_info
            
            poco.click([0.5, (pos[1] + 50) / displayInfo["height"]])
            
            text("自动化测试分享", False)
            
            assert_exists(Template(r"tpl1534501448515.png", record_pos=(0.255, 0.353), resolution=(1080, 1920)), "点击分享")

            touch(Template(r"tpl1534501448515.png", record_pos=(0.255, 0.353), resolution=(1080, 1920)))
            
            assert_exists(Template(r"tpl1534501706881.png", record_pos=(-0.162, 0.203), resolution=(1080, 1920)), "请填写测试点")
            
            touch(Template(r"tpl1534501706881.png", record_pos=(-0.162, 0.203), resolution=(1080, 1920)))
        except:
            print("")
        
        sleep(1.0) # 等待界面切回来

        poco.click([0.7, 0.5])

        return True
        
_instance = SideMenu_Share()
runTest = _instance.runTest

